
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include <cinvoke.h>

#include "reflecxx.h"

void myfunc(char *buffer, int a, float b)
{
    sprintf(buffer, "%d -> %.2f\n", a, b);
}

extern struct reflecxx_full_type myfunc_type_info;

int main(int argc, char *argv[])
{
    struct reflecxx_function *fun;
    int retval = EXIT_SUCCESS;
    CInvFunction *cf;
    CInvContext *cc;
    
    fun = myfunc_type_info.rft_type_info.fun;

    cc = cinv_context_create();
    assert(cc != NULL);

    cf = cinv_function_create(cc,
			      CINV_CC_DEFAULT, 
			      fun->rf_cinv_return,
			      fun->rf_cinv_parameters);
    assert(cf != NULL);

    {
	char buffer[1024];
	void *bufptr = buffer;
	float b = 3.14;
	int a = 5;

	void *args[] = { &bufptr, &a, &b };

	cinv_function_invoke(cc, cf, myfunc, NULL, args);
	assert(strcmp(buffer, "5 -> 3.14\n") == 0);
    }
    
    cinv_context_delete(cc);
    
    return retval;
}
